<!DOCTYPE html>
          <head>
        <meta charset="utf-8">
            
            <title>
                「Android」各种小记录 | ttdevs
            </title>
            <meta content="width=device-width, initial-scale=1" name="viewport">
            <meta name="theme-color" content="#4184f3">
            
            
            <link href="/favicon.ico" rel="icon"/>
            

            <link rel="stylesheet" href="/css/highlight.light.css">
            <link rel="stylesheet" href="/css/prism-customize.css">
            <link rel="stylesheet" href="/css/nav-icon.css">
            <link rel="stylesheet" href="/css/waves.min.css">
            <link rel="stylesheet" href="/css/jquery.tocify.css">
            <link rel="stylesheet" href="/css/main.css">
            <link rel="stylesheet" href="/css/nav-indicator.css">
            
  

  
  <!-- 谷歌统计 -->
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-97465173-1', 'auto');
    ga('send', 'pageview');

  </script>
  
            </meta>
        </meta>
    </head>

    <body>
        <header>
            <!-- cover image or sth. -->
        </header>
        <div id="main" class="m-scene">
            
<div class="nav-wrapper">

    <div class="container">
        <nav>
            <div class="logo wave">
                <a href="/" id="logo">
                    ttdevs
                </a>
            </div>
            <div class="nav-toggle-icon" >
                <div class="material-hamburger">
                    <span>
                    </span>
                    <span>
                    </span>
                    <span>
                    </span>
                </div>
            </div>
            <div class="menu-wrapper">
                <div class="nav-indicator">
                </div>
                <ul class="menus">
                    
                     
                        <li>
                            <a class="wave " href="/">
                                首页
                            </a>
                        </li>
                     
                        <li>
                            <a class="wave " href="/archives">
                                归档
                            </a>
                        </li>
                     
                        <li>
                            <a class="wave " href="/about">
                                关于
                            </a>
                        </li>
                     
                    
                   
                </ul>
            </div>
        </nav>
    </div>
</div>
            <div class="container content">
                <div class="scene_element scene_element--fadein">
                    <div class="row">
    <div class="main">
        <article>
          
          <header class="post-header with-cover" style="background-image:url('/1970/01/01/[Android]各种小记录/cover.jpg')" >
          
          </header>
          <h1 class="post-title">「Android」各种小记录</h1>

          <section class="post-info">
            <span class="post-date">1970/01/01</span>
            
            <span class="post-category">
                <a class="article-category-link" href="/categories/技术/">技术</a>
            </span>
            
            
            <span class="post-tags">
              <ul class="post-tag-list"><li class="post-tag-list-item"><a class="post-tag-list-link" href="/tags/Android/">Android</a></li></ul>
            </span>
            
          </section>

          <section class="post-content">
            <h2 id="0x00-小记录"><a href="/1970/01/01/[Android]各种小记录/#0x00-小记录" class="headerlink" title="0x00 小记录"></a>0x00 小记录</h2><p>这里是一些零碎知识点</p>
<h2 id="0x01-sqlite中处理单引号"><a href="/1970/01/01/[Android]各种小记录/#0x01-sqlite中处理单引号" class="headerlink" title="0x01 sqlite中处理单引号"></a>0x01 sqlite中处理单引号</h2><p>所有单引号换成双单引号，如：</p>
<p><code>content.replace(&quot;&#39;&quot;, &quot;&#39;&#39;&quot;);</code></p>
<p>这样是不行的，临时抱佛脚，换成了带”？”的通配形式</p>
<h2 id="0x02-SimpleCursorAdapter-notifyDataSetChanged无效"><a href="/1970/01/01/[Android]各种小记录/#0x02-SimpleCursorAdapter-notifyDataSetChanged无效" class="headerlink" title="0x02 SimpleCursorAdapter.notifyDataSetChanged无效"></a>0x02 SimpleCursorAdapter.notifyDataSetChanged无效</h2><p>可以使用SimpleCursorAdapter的changeCursor方法：</p>
<ul>
<li><a href="http://stackoverflow.com/questions/1985955/android-simplecursoradapter-not-updating-with-database-changes" target="_blank" rel="external">http://stackoverflow.com/questions/1985955/android-simplecursoradapter-not-updating-with-database-changes</a></li>
<li><a href="http://stackoverflow.com/questions/14034770/using-notifydatasetchanged-on-simplecursoradapter-does-not-work" target="_blank" rel="external">http://stackoverflow.com/questions/14034770/using-notifydatasetchanged-on-simplecursoradapter-does-not-work</a>  </li>
</ul>
<h2 id="0x03-listview隐藏分割线"><a href="/1970/01/01/[Android]各种小记录/#0x03-listview隐藏分割线" class="headerlink" title="0x03 listview隐藏分割线"></a>0x03 listview隐藏分割线</h2><ul>
<li><code>setDriver(null)</code> </li>
<li>在xml文件中属性设置为 <code>@null</code></li>
</ul>
<h2 id="0x04-sqlite中replace-into无效"><a href="/1970/01/01/[Android]各种小记录/#0x04-sqlite中replace-into无效" class="headerlink" title="0x04 sqlite中replace into无效"></a>0x04 sqlite中replace into无效</h2><p>之前写好的代码调试都通过了，今天突然发现不能运行了：</p>
<blockquote>
<p>sqlite，表中创建唯一索引，然后使用replace into实现插入或者更新，结果变成了只插入</p>
</blockquote>
<p>折腾了几个小时，最后改掉了表中一个名为id的字段，实在是无语</p>
<h2 id="0x05-临时写java的Thread封装"><a href="/1970/01/01/[Android]各种小记录/#0x05-临时写java的Thread封装" class="headerlink" title="0x05 临时写java的Thread封装"></a>0x05 临时写java的Thread封装</h2><figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div></pre></td><td class="code"><pre><div class="line">public abstract class BaseThread extends Thread &#123;</div><div class="line"></div><div class="line">    private volatile boolean mQuit = false;</div><div class="line"></div><div class="line">    public BaseThread() &#123;</div><div class="line"></div><div class="line">    &#125;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * prepare if needed</div><div class="line">     */</div><div class="line">    public boolean prepare() &#123;</div><div class="line"></div><div class="line">        return true;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * run body</div><div class="line">     */</div><div class="line">    public abstract void execute() throws Exception; // third modify,second modify maybe not neccessary</div><div class="line"></div><div class="line">    /**</div><div class="line">     * recycle if needed</div><div class="line">     */</div><div class="line">    public void recycle() &#123;</div><div class="line"></div><div class="line">    &#125;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * stop thread</div><div class="line">     */</div><div class="line">    public final void quit() &#123;</div><div class="line">        mQuit = true;</div><div class="line">        interrupt();</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    @Override</div><div class="line">    public void run() &#123;</div><div class="line">        // TODO</div><div class="line">        Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);</div><div class="line">        if (!prepare()) &#123;</div><div class="line">            return;</div><div class="line">        &#125;</div><div class="line">        while (true) &#123;</div><div class="line">            if (mQuit) &#123; // second modify</div><div class="line">                recycle();</div><div class="line">                return;</div><div class="line">            &#125;</div><div class="line">            try &#123;</div><div class="line">                execute();</div><div class="line">            &#125; catch (Exception e) &#123;// &#125; catch (InterruptedException e) &#123;</div><div class="line">                if (mQuit) &#123;</div><div class="line">                    recycle();</div><div class="line">                    return;</div><div class="line">                &#125;</div><div class="line">                continue;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line">```  </div><div class="line"></div><div class="line"></div><div class="line">## 0x06 Volley中设置连接超时</div><div class="line"></div><div class="line">设置超时的地方：</div><div class="line"></div><div class="line">HurlStack：</div><div class="line"></div><div class="line">``` java</div><div class="line">/**</div><div class="line">* Opens an &#123;@link HttpURLConnection&#125; with parameters.</div><div class="line">*</div><div class="line">* @param url</div><div class="line">* @return an open connection</div><div class="line">* @throws IOException</div><div class="line">*/</div><div class="line">private HttpURLConnection openConnection(URL url, Request&lt;?&gt; request) throws IOException &#123;</div><div class="line">   HttpURLConnection connection = createConnection(url);</div><div class="line"></div><div class="line">   int timeoutMs = request.getTimeoutMs();</div><div class="line">   connection.setConnectTimeout(timeoutMs);</div><div class="line">   connection.setReadTimeout(timeoutMs);</div><div class="line">   connection.setUseCaches(false);</div><div class="line">   connection.setDoInput(true);</div><div class="line"></div><div class="line">   // use caller-provided custom SslSocketFactory, if any, for HTTPS</div><div class="line">   if ("https".equals(url.getProtocol()) &amp;&amp; mSslSocketFactory != null) &#123;</div><div class="line">       ((HttpsURLConnection) connection).setSSLSocketFactory(mSslSocketFactory);</div><div class="line">   &#125;</div><div class="line"></div><div class="line">   return connection;</div><div class="line">&#125;</div><div class="line">```    </div><div class="line"></div><div class="line">HttpClientStack：  </div><div class="line"></div><div class="line">``` java</div><div class="line">@Override</div><div class="line">public HttpResponse performRequest(Request&lt;?&gt; request, Map&lt;String, String&gt; additionalHeaders)</div><div class="line">        throws IOException, AuthFailureError &#123;</div><div class="line">    HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders);</div><div class="line">    addHeaders(httpRequest, additionalHeaders);</div><div class="line">    addHeaders(httpRequest, request.getHeaders());</div><div class="line">    onPrepareRequest(httpRequest);</div><div class="line">    HttpParams httpParams = httpRequest.getParams();</div><div class="line">    int timeoutMs = request.getTimeoutMs();</div><div class="line">    // TODO: Reevaluate this connection timeout based on more wide-scale</div><div class="line">    // data collection and possibly different for wifi vs. 3G.</div><div class="line">    HttpConnectionParams.setConnectionTimeout(httpParams, 5000);</div><div class="line">    HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);</div><div class="line">    return mClient.execute(httpRequest);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>Request中：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line">* Sets the retry policy for this request.</div><div class="line">*/</div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setRetryPolicy</span><span class="params">(RetryPolicy retryPolicy)</span> </span>&#123;</div><div class="line">   mRetryPolicy = retryPolicy;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>RetryPolicy ：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line">* Retry policy for a request.</div><div class="line">*/</div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">RetryPolicy</span> </span>&#123;</div><div class="line"></div><div class="line">   <span class="comment">/**</span></div><div class="line">    * Returns the current timeout (used for logging).</div><div class="line">    */</div><div class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getCurrentTimeout</span><span class="params">()</span></span>;</div><div class="line"></div><div class="line">   <span class="comment">/**</span></div><div class="line">    * Returns the current retry count (used for logging).</div><div class="line">    */</div><div class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getCurrentRetryCount</span><span class="params">()</span></span>;</div><div class="line"></div><div class="line">   <span class="comment">/**</span></div><div class="line">    * Prepares for the next retry by applying a backoff to the timeout.</div><div class="line">    *</div><div class="line">    * <span class="doctag">@param</span> error The error code of the last attempt.</div><div class="line">    * <span class="doctag">@throws</span> VolleyError In the event that the retry could not be performed (for example if we</div><div class="line">    *                     ran out of attempts), the passed in error is thrown.</div><div class="line">    */</div><div class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">retry</span><span class="params">(VolleyError error)</span> <span class="keyword">throws</span> VolleyError</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="0x07-Android与图片相关"><a href="/1970/01/01/[Android]各种小记录/#0x07-Android与图片相关" class="headerlink" title="0x07 Android与图片相关"></a>0x07 Android与图片相关</h2><p><a href="http://developer.android.com/training/displaying-bitmaps/index.html" target="_blank" rel="external">http://developer.android.com/training/displaying-bitmaps/index.html</a>  </p>
<h2 id="0x08-将eclipse项目中的文件夹移除SVN的控制（添加到svn-ignore）"><a href="/1970/01/01/[Android]各种小记录/#0x08-将eclipse项目中的文件夹移除SVN的控制（添加到svn-ignore）" class="headerlink" title="0x08 将eclipse项目中的文件夹移除SVN的控制（添加到svn:ignore）"></a>0x08 将eclipse项目中的文件夹移除SVN的控制（添加到svn:ignore）</h2><p>以删除android项目中的bin文件夹为例</p>
<p>a、关闭项目的自动build：project-Build Automatically<br>b、删除bin文件夹<br>c、提交<br>d、打开 项目的自动build，这个时候会生成bin文件夹<br>e、将bin添加到svn:ignore：右键-Team-添加至svn:ignore<br>f、提交</p>
<h2 id="0x09-屏幕旋转，Activity的成员变量被全部释放？！"><a href="/1970/01/01/[Android]各种小记录/#0x09-屏幕旋转，Activity的成员变量被全部释放？！" class="headerlink" title="0x09 屏幕旋转，Activity的成员变量被全部释放？！"></a>0x09 屏幕旋转，Activity的成员变量被全部释放？！</h2><p>貌似是这样子的</p>
<h2 id="0x10-ViewPager频繁被回收"><a href="/1970/01/01/[Android]各种小记录/#0x10-ViewPager频繁被回收" class="headerlink" title="0x10 ViewPager频繁被回收"></a>0x10 ViewPager频繁被回收</h2><p><a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit\(int\" target="_blank" rel="external">ViewPager</a>)  </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line">* Set the number of pages that should be retained to either side of the</div><div class="line">* current page in the view hierarchy in an idle state. Pages beyond this</div><div class="line">* limit will be recreated from the adapter when needed.</div><div class="line">*</div><div class="line">* &lt;p&gt;This is offered as an optimization. If you know in advance the number</div><div class="line">* of pages you will need to support or have lazy-loading mechanisms in place</div><div class="line">* on your pages, tweaking this setting can have benefits in perceived smoothness</div><div class="line">* of paging animations and interaction. If you have a small number of pages (3-4)</div><div class="line">* that you can keep active all at once, less time will be spent in layout for</div><div class="line">* newly created view subtrees as the user pages back and forth.&lt;/p&gt;</div><div class="line">*</div><div class="line">* &lt;p&gt;You should keep this limit low, especially if your pages have complex layouts.</div><div class="line">* This setting defaults to 1.&lt;/p&gt;</div><div class="line">*</div><div class="line">* <span class="doctag">@param</span> limit How many pages will be kept offscreen in an idle state.</div><div class="line">*/</div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setOffscreenPageLimit</span><span class="params">(<span class="keyword">int</span> limit)</span> </span>&#123;</div><div class="line">   <span class="keyword">if</span> (limit &lt; DEFAULT_OFFSCREEN_PAGES) &#123;</div><div class="line">       Log.w(TAG, <span class="string">"Requested offscreen page limit "</span> + limit + <span class="string">" too small; defaulting to "</span></div><div class="line">               + DEFAULT_OFFSCREEN_PAGES);</div><div class="line">       limit = DEFAULT_OFFSCREEN_PAGES;</div><div class="line">   &#125;</div><div class="line">   <span class="keyword">if</span> (limit != mOffscreenPageLimit) &#123;</div><div class="line">       mOffscreenPageLimit = limit;</div><div class="line">       populate();</div><div class="line">   &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="0x11-Android-SQLite-分页查询，参数为页大小和起始编号"><a href="/1970/01/01/[Android]各种小记录/#0x11-Android-SQLite-分页查询，参数为页大小和起始编号" class="headerlink" title="0x11 Android SQLite 分页查询，参数为页大小和起始编号"></a>0x11 Android SQLite 分页查询，参数为页大小和起始编号</h2><p>先看数据：</p>
<p><img src="http://img.blog.csdn.net/20131126171733656?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdHRkZXZz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">  </p>
<p>查询第0条之后的5条：<br><code>select * from china_city where province = &#39;北京&#39; order by code limit 5 offset 0</code></p>
<p><img src="http://img.blog.csdn.net/20131126171744390?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdHRkZXZz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">  </p>
<p>查询第5条之后的5条：<br><code>select * from china_city where province = &#39;北京&#39; order by code limit 5 offset 5</code></p>
<p><img src="http://img.blog.csdn.net/20131126171750843?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdHRkZXZz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">  </p>
<h2 id="0x12-获取进程内存-和-已使用内存"><a href="/1970/01/01/[Android]各种小记录/#0x12-获取进程内存-和-已使用内存" class="headerlink" title="0x12 获取进程内存 和 已使用内存"></a>0x12 获取进程内存 和 已使用内存</h2><ul>
<li>进程内存</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">int</span> memClass = ((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();</div><div class="line"></div><div class="line"><span class="keyword">int</span> maxMemory = (<span class="keyword">int</span>) (Runtime.getRuntime().maxMemory() / <span class="number">1024</span>);</div></pre></td></tr></table></figure>
<ul>
<li><p>已使用内存</p>
<p>  <code>Log.i(&quot;tag&quot;, where+&quot;usedMemory: &quot;+Debug.getNativeHeapSize()/ 1048576L);</code></p>
</li>
</ul>
<h2 id="0x13-与联系人相关"><a href="/1970/01/01/[Android]各种小记录/#0x13-与联系人相关" class="headerlink" title="0x13 与联系人相关"></a>0x13 与联系人相关</h2><p><a href="http://developer.android.com/training/contacts-provider/display-contact-badge.html" target="_blank" rel="external">http://developer.android.com/training/contacts-provider/display-contact-badge.html </a>  </p>
<h2 id="0x14-设置字体大小"><a href="/1970/01/01/[Android]各种小记录/#0x14-设置字体大小" class="headerlink" title="0x14 设置字体大小"></a>0x14 设置字体大小</h2><p>可以用setTextSize()的另外一种形式，可以指定单位：<br><code>setTextSize(int unit, int size)</code></p>
<ul>
<li>TypedValue.COMPLEX_UNIT_PX: Pixels</li>
<li>TypedValue.COMPLEX_UNIT_SP: Scaled Pixels</li>
<li>TypedValue.COMPLEX_UNIT_DIP: Device Independent Pixels</li>
</ul>
<h2 id="0x15-交换两个变量的值"><a href="/1970/01/01/[Android]各种小记录/#0x15-交换两个变量的值" class="headerlink" title="0x15 交换两个变量的值"></a>0x15 交换两个变量的值</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">date3 = date1;</div><div class="line">date1 = date2;</div><div class="line">date2 = date3;</div></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">if</span> (date2 &gt; date1) &#123;</div><div class="line">    date2 = date2 + date1;</div><div class="line">    date1 = date2 - date1;</div><div class="line">    date2 = date2 - date1;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">date2 = date1 ^ date2;</div><div class="line">date1 = date1 ^ date2;</div><div class="line">date2 = date1 ^ date2;</div></pre></td></tr></table></figure>
<h2 id="0x16-获取URI真实的地址"><a href="/1970/01/01/[Android]各种小记录/#0x16-获取URI真实的地址" class="headerlink" title="0x16 获取URI真实的地址"></a>0x16 获取URI真实的地址</h2><figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div></pre></td><td class="code"><pre><div class="line">private String getRealPath(Uri uri) &#123;</div><div class="line">   String path = "";</div><div class="line">   String[] proj = &#123;MediaStore.Images.Media.DATA&#125;;</div><div class="line">   Cursor cursor = getActivity().getContentResolver().query(uri, proj, null, null, null);</div><div class="line">   if (cursor != null &amp;&amp; cursor.moveToFirst()) &#123;</div><div class="line">       path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));</div><div class="line">   &#125;</div><div class="line">   return path;</div><div class="line">&#125;</div><div class="line">```  </div><div class="line"></div><div class="line"></div><div class="line">## 0x17 自定义Gridview，解决ScrollView中嵌套Gridview显示不正常的问题</div><div class="line"></div><div class="line">网上到处都可以找到下面的解决办法，但是这样会有一个问题：当图片非常多的时候是一次加载完毕的，而我们希望的应该是本来的GridView可以通过滑动判断当前显示</div><div class="line">条目的情况，在此记录一下。</div><div class="line"></div><div class="line">``` java</div><div class="line">/**</div><div class="line">* 自定义Gridview，解决ScrollView中嵌套Gridview显示不正常的问题&lt;br&gt;</div><div class="line">* 但是，这又产生了一个新的问题：所有的item都是一次加载完毕的，再想滑动加载就不行了</div><div class="line">*</div><div class="line">* @author ttdevs</div><div class="line">*/</div><div class="line">public class ImageGridView extends GridView &#123;</div><div class="line">   public ImageGridView(Context context) &#123;</div><div class="line">       this(context, null);</div><div class="line">   &#125;</div><div class="line"></div><div class="line">   public ImageGridView(Context context, AttributeSet attrs) &#123;</div><div class="line">       this(context, attrs, 0);</div><div class="line">   &#125;</div><div class="line"></div><div class="line">   public ImageGridView(Context context, AttributeSet attrs, int defStyle) &#123;</div><div class="line">       super(context, attrs, defStyle);</div><div class="line">   &#125;</div><div class="line"></div><div class="line">   @Override</div><div class="line">   public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) &#123;</div><div class="line">       //super.onMeasure(widthMeasureSpec, heightMeasureSpec);</div><div class="line">       int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE &gt;&gt; 2, MeasureSpec.AT_MOST);</div><div class="line">       super.onMeasure(widthMeasureSpec, expandSpec);</div><div class="line">   &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="0x18-9图片的制作"><a href="/1970/01/01/[Android]各种小记录/#0x18-9图片的制作" class="headerlink" title="0x18 .9图片的制作"></a>0x18 .9图片的制作</h2><p>一个图片只想横向拉伸。所以就想当然的只在左边画了一条横线，运行的时候怎么都是有黑线，没拉伸。</p>
<p><code>最后解决：给左边也加一条竖线！</code></p>
<h2 id="0x20-listview点击背景不变"><a href="/1970/01/01/[Android]各种小记录/#0x20-listview点击背景不变" class="headerlink" title="0x20 listview点击背景不变"></a>0x20 listview点击背景不变</h2><p>这个应该还是焦点的问题，在item的view最上层布局中添加一个属性：</p>
<p><code>android:descendantFocusability=&quot;blocksDescendants&quot;</code></p>
<h2 id="0x21-Volley-Cookies"><a href="/1970/01/01/[Android]各种小记录/#0x21-Volley-Cookies" class="headerlink" title="0x21 Volley Cookies"></a>0x21 Volley Cookies</h2><p><a href="http://stackoverflow.com/questions/16680701/using-cookies-with-android-volley-library" target="_blank" rel="external">http://stackoverflow.com/questions/16680701/using-cookies-with-android-volley-library</a></p>
<h2 id="0x22-EditText设置readOnly"><a href="/1970/01/01/[Android]各种小记录/#0x22-EditText设置readOnly" class="headerlink" title="0x22 EditText设置readOnly"></a>0x22 EditText设置readOnly</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">et.setCursorVisible(<span class="keyword">false</span>); </div><div class="line">et.setFocusable(<span class="keyword">false</span>); </div><div class="line">et.setFocusableInTouchMode(<span class="keyword">false</span>);</div></pre></td></tr></table></figure>
<h2 id="0x23-保存对象到SharedPreferences"><a href="/1970/01/01/[Android]各种小记录/#0x23-保存对象到SharedPreferences" class="headerlink" title="0x23 保存对象到SharedPreferences"></a>0x23 保存对象到SharedPreferences</h2><p>想保存一个List<javabean> 到SharedPreferences。网上找了一圈有一种说法利用set，或者base64，都感觉不好。朋友一句提示：json。然后豁然开朗。现转化成json，然后保存，效果不错。</javabean></p>
<h2 id="0x24-获取字符"><a href="/1970/01/01/[Android]各种小记录/#0x24-获取字符" class="headerlink" title="0x24 获取字符"></a>0x24 获取字符</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> String <span class="title">getCharacter</span><span class="params">(String str)</span> </span>&#123;</div><div class="line">    StringBuilder sb = <span class="keyword">new</span> StringBuilder();</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; str.length(); i++) &#123;</div><div class="line">        <span class="keyword">if</span> (String.valueOf(str.charAt(i)).getBytes().length &gt; <span class="number">1</span>) &#123;</div><div class="line">            sb.append(str.charAt(i));</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">return</span> sb.toString();</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="0x25-Android-4-按钮样式"><a href="/1970/01/01/[Android]各种小记录/#0x25-Android-4-按钮样式" class="headerlink" title="0x25 Android 4 按钮样式"></a>0x25 Android 4 按钮样式</h2><p><code>style=&quot;?android:attr/buttonBarButtonStyle&quot;</code></p>
<h2 id="0x26-几个sqlite的sql语句"><a href="/1970/01/01/[Android]各种小记录/#0x26-几个sqlite的sql语句" class="headerlink" title="0x26 几个sqlite的sql语句"></a>0x26 几个sqlite的sql语句</h2><ul>
<li>select count(*) from notes</li>
<li>create table notes_new as select * from notes;</li>
<li>select count(*) from notes_new</li>
<li>delete from notes_new where word like ‘% %’;</li>
<li>delete from notes_new where word like ‘%-%’;</li>
<li>delete from notes_new where phonetic like ‘’;</li>
<li>create table notes_new_new as select * from notes_new;</li>
<li>select count(*) from notes_new_new</li>
<li>delete from notes_new_new where _id not in (select min(_id) from notes_new_new group by word)</li>
<li>select * from notes_new_new</li>
<li>insert into notes_word(word,detail,created,phonetic) select word,detail,created,phonetic from notes_new_new;</li>
<li><p>Create Table:</p>
  <figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> notes_word(</div><div class="line">        _id <span class="built_in">INTEGER</span> PRIMARY <span class="keyword">KEY</span> AUTOINCREMENT,</div><div class="line">        word <span class="built_in">TEXT</span>,</div><div class="line">        detail <span class="built_in">TEXT</span>,</div><div class="line">        created <span class="built_in">INT</span>,</div><div class="line">        phonetic <span class="built_in">TEXT</span></div><div class="line">);</div></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="0x27-加密相关"><a href="/1970/01/01/[Android]各种小记录/#0x27-加密相关" class="headerlink" title="0x27 加密相关"></a>0x27 加密相关</h2><ul>
<li><a href="http://blog.csdn.net/androidsecurity/article/details/8666954" target="_blank" rel="external">http://blog.csdn.net/androidsecurity/article/details/8666954</a>  </li>
<li><a href="http://blog.csdn.net/baolong47/article/details/17335227" target="_blank" rel="external">http://blog.csdn.net/baolong47/article/details/17335227</a>  </li>
<li><a href="http://blog.csdn.net/guolin_blog/article/details/11952409" target="_blank" rel="external">http://blog.csdn.net/guolin_blog/article/details/11952409</a>  </li>
</ul>
<h2 id="0x28-FaceBook开源项目"><a href="/1970/01/01/[Android]各种小记录/#0x28-FaceBook开源项目" class="headerlink" title="0x28 FaceBook开源项目"></a>0x28 FaceBook开源项目</h2><p><a href="http://facebook.github.io/rebound/" target="_blank" rel="external"></a></p>
<h2 id="0x29-ScrollView与高度固定的GridView或者ListView嵌套时，界面不显示在最上面"><a href="/1970/01/01/[Android]各种小记录/#0x29-ScrollView与高度固定的GridView或者ListView嵌套时，界面不显示在最上面" class="headerlink" title="0x29 ScrollView与高度固定的GridView或者ListView嵌套时，界面不显示在最上面"></a>0x29 ScrollView与高度固定的GridView或者ListView嵌套时，界面不显示在最上面</h2><ul>
<li><p>gvGroup.setFocusable(false);</p>
<p>  lvGroup.setFocusable(false);在设置Adapter之前让其失去焦点</p>
</li>
<li><p>svMain.fullScroll(ScrollView.FOCUS_UP);</p>
<p>  在合适的时候(如delay10ms)让ScrollView滚动到最顶端</p>
</li>
</ul>
<h2 id="0x30-获取view的高度"><a href="/1970/01/01/[Android]各种小记录/#0x30-获取view的高度" class="headerlink" title="0x30 获取view的高度"></a>0x30 获取view的高度</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">Rect rect = <span class="keyword">new</span> Rect();</div><div class="line">getDrawingRect(rect);</div><div class="line"><span class="keyword">int</span> height = rect.bottom - rect.top;</div></pre></td></tr></table></figure>
<h2 id="0x31-http-hold-on-iteye-com-blog-1943437"><a href="/1970/01/01/[Android]各种小记录/#0x31-http-hold-on-iteye-com-blog-1943437" class="headerlink" title="0x31 http://hold-on.iteye.com/blog/1943437"></a>0x31 <a href="http://hold-on.iteye.com/blog/1943437" target="_blank" rel="external">http://hold-on.iteye.com/blog/1943437</a></h2><h2 id="0x32-调用系统的浏览器打开网页"><a href="/1970/01/01/[Android]各种小记录/#0x32-调用系统的浏览器打开网页" class="headerlink" title="0x32 调用系统的浏览器打开网页"></a>0x32 调用系统的浏览器打开网页</h2><p><code>区分大小写，http必须为小写</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">String url = <span class="string">"http://www.baidu.com"</span>;</div><div class="line">Intent intent = <span class="keyword">new</span> Intent(Intent.ACTION_VIEW);</div><div class="line">intent.setData(Uri.parse(url));</div><div class="line">startActivity(intent);</div></pre></td></tr></table></figure>
<h2 id="0x33-HTTP-POST-乱码"><a href="/1970/01/01/[Android]各种小记录/#0x33-HTTP-POST-乱码" class="headerlink" title="0x33 HTTP POST 乱码"></a>0x33 HTTP POST 乱码</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">List&lt;NameValuePair&gt; postParameters = <span class="keyword">new</span> ArrayList&lt;NameValuePair&gt;();</div><div class="line">postParameters.add(<span class="keyword">new</span> BasicNameValuePair(<span class="string">"v"</span>, param));</div><div class="line">postParameters.add(<span class="keyword">new</span> BasicNameValuePair(<span class="string">"s"</span>, Utils.MD5Encode(param, <span class="string">""</span>)));</div><div class="line">postParameters.add(<span class="keyword">new</span> BasicNameValuePair(<span class="string">"e"</span>, String.valueOf(encryptType)));</div><div class="line"></div><div class="line">UrlEncodedFormEntity formEntity = <span class="keyword">new</span> UrlEncodedFormEntity(postParameters, <span class="string">"UTF-8"</span>);</div><div class="line">mPost.setEntity(formEntity);</div></pre></td></tr></table></figure>
<h2 id="0x34-读取联系人"><a href="/1970/01/01/[Android]各种小记录/#0x34-读取联系人" class="headerlink" title="0x34 读取联系人"></a>0x34 读取联系人</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * 读取本地通讯录（手机）&lt;br&gt;</div><div class="line"> * 用户通讯录： 手机号码、联系人命名、备注信息、分组信息&lt;br&gt;</div><div class="line"> * 耗时</div><div class="line"> *</div><div class="line"> * <span class="doctag">@param</span> context</div><div class="line"> * <span class="doctag">@return</span></div><div class="line"> */</div><div class="line"><span class="meta">@SuppressLint</span>(<span class="string">"UseSparseArrays"</span>)</div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> Map&lt;String, ContactInfo&gt; <span class="title">getContracts</span><span class="params">(Context context)</span> </span>&#123;</div><div class="line">    Map&lt;String, ContactInfo&gt; contactMap = <span class="keyword">new</span> HashMap&lt;String, ContactInfo&gt;();</div><div class="line">    <span class="keyword">try</span> &#123;</div><div class="line"></div><div class="line">        ContentResolver resolver = context.getContentResolver();</div><div class="line">        <span class="keyword">if</span> (<span class="keyword">null</span> == resolver) &#123;</div><div class="line">            <span class="keyword">return</span> contactMap;</div><div class="line">        &#125;</div><div class="line">        <span class="comment">// 手机：姓名和手机号</span></div><div class="line">        Cursor curosr = resolver.query(Phone.CONTENT_URI, <span class="keyword">new</span> String[]&#123;Phone.CONTACT_ID, Phone.DISPLAY_NAME, Phone.NUMBER&#125;, <span class="keyword">null</span>, <span class="keyword">null</span>, <span class="keyword">null</span>);</div><div class="line">        <span class="keyword">if</span> (<span class="keyword">null</span> != curosr &amp;&amp; curosr.moveToFirst()) &#123;</div><div class="line">            <span class="keyword">int</span> keyId = curosr.getColumnIndex(Phone.CONTACT_ID);</div><div class="line">            <span class="keyword">int</span> keyName = curosr.getColumnIndex(Phone.DISPLAY_NAME);</div><div class="line">            <span class="keyword">int</span> keyNumber = curosr.getColumnIndex(Phone.NUMBER);</div><div class="line">            <span class="keyword">do</span> &#123;</div><div class="line">                String id = curosr.getString(keyId);</div><div class="line">                String name = curosr.getString(keyName);</div><div class="line">                String number = curosr.getString(keyNumber);</div><div class="line">                ContactInfo info = <span class="keyword">new</span> ContactInfo();</div><div class="line">                info.setName(name);</div><div class="line">                <span class="keyword">if</span> (!TextUtils.isEmpty(number)) &#123;</div><div class="line">                    number = number.replace(<span class="string">"-"</span>, <span class="string">""</span>);</div><div class="line">                    number = number.replace(<span class="string">" "</span>, <span class="string">""</span>);</div><div class="line">                    info.setNumber(number);</div><div class="line">                &#125;</div><div class="line">                contactMap.put(id, info);</div><div class="line">            &#125; <span class="keyword">while</span> (curosr.moveToNext());</div><div class="line">        &#125;</div><div class="line">        curosr.close();</div><div class="line"></div><div class="line">        <span class="comment">// SIM卡：姓名和手机号</span></div><div class="line">        curosr = resolver.query(Uri.parse(<span class="string">"content://icc/adn"</span>), <span class="keyword">new</span> String[]&#123;Phone.CONTACT_ID, Phone.DISPLAY_NAME, Phone.NUMBER&#125;, <span class="keyword">null</span>, <span class="keyword">null</span>, <span class="keyword">null</span>);</div><div class="line">        <span class="keyword">if</span> (<span class="keyword">null</span> != curosr &amp;&amp; curosr.moveToFirst()) &#123;</div><div class="line">            <span class="keyword">int</span> keyId = curosr.getColumnIndex(Phone.CONTACT_ID);</div><div class="line">            <span class="keyword">int</span> keyName = curosr.getColumnIndex(Phone.DISPLAY_NAME);</div><div class="line">            <span class="keyword">int</span> keyNumber = curosr.getColumnIndex(Phone.NUMBER);</div><div class="line">            <span class="keyword">do</span> &#123;</div><div class="line">                String id = curosr.getString(keyId);</div><div class="line">                String name = curosr.getString(keyName);</div><div class="line">                String number = curosr.getString(keyNumber);</div><div class="line">                ContactInfo info = <span class="keyword">new</span> ContactInfo();</div><div class="line">                info.setName(name);</div><div class="line">                info.setNumber(number);</div><div class="line">                contactMap.put(id, info);</div><div class="line">            &#125; <span class="keyword">while</span> (curosr.moveToNext());</div><div class="line">        &#125;</div><div class="line">        curosr.close();</div><div class="line"></div><div class="line">        <span class="comment">// 备注</span></div><div class="line">        curosr = resolver.query(Data.CONTENT_URI, <span class="keyword">new</span> String[]&#123;Data.CONTACT_ID, Data.DATA1&#125;, <span class="keyword">null</span>, <span class="keyword">null</span>, <span class="keyword">null</span>);</div><div class="line">        <span class="keyword">if</span> (<span class="keyword">null</span> != curosr &amp;&amp; curosr.moveToFirst()) &#123;</div><div class="line">            <span class="keyword">int</span> keyId = curosr.getColumnIndex(Data.CONTACT_ID);</div><div class="line">            <span class="keyword">int</span> keyRemark = curosr.getColumnIndex(Data.DATA1);</div><div class="line">            <span class="keyword">do</span> &#123;</div><div class="line">                String id = curosr.getString(keyId);</div><div class="line">                String remark = curosr.getString(keyRemark);</div><div class="line">                ContactInfo info = contactMap.get(id);</div><div class="line">                <span class="keyword">if</span> (<span class="keyword">null</span> != info) &#123;</div><div class="line">                    info.setRemark(remark);</div><div class="line">                &#125;</div><div class="line">            &#125; <span class="keyword">while</span> (curosr.moveToNext());</div><div class="line">        &#125;</div><div class="line">        curosr.close();</div><div class="line"></div><div class="line">        <span class="comment">// 获取所有分组</span></div><div class="line">        Map&lt;String, String&gt; groupData = <span class="keyword">new</span> HashMap&lt;String, String&gt;();</div><div class="line">        curosr = resolver.query(Groups.CONTENT_URI, <span class="keyword">new</span> String[]&#123;Groups._ID, Groups.TITLE&#125;, <span class="keyword">null</span>, <span class="keyword">null</span>, <span class="keyword">null</span>);</div><div class="line">        <span class="keyword">if</span> (<span class="keyword">null</span> != curosr &amp;&amp; curosr.moveToFirst()) &#123;</div><div class="line">            <span class="keyword">int</span> keyId = curosr.getColumnIndex(Groups._ID);</div><div class="line">            <span class="keyword">int</span> keyGroupName = curosr.getColumnIndex(Groups.TITLE);</div><div class="line">            <span class="keyword">do</span> &#123;</div><div class="line">                String id = curosr.getString(keyId);</div><div class="line">                String name = curosr.getString(keyGroupName);</div><div class="line">                groupData.put(id, name);</div><div class="line">            &#125; <span class="keyword">while</span> (curosr.moveToNext());</div><div class="line">        &#125;</div><div class="line">        curosr.close();</div><div class="line"></div><div class="line">        <span class="comment">// 关联联系人和分组</span></div><div class="line">        curosr = resolver.query(Data.CONTENT_URI, <span class="keyword">new</span> String[]&#123;GroupMembership.CONTACT_ID, GroupMembership.GROUP_ROW_ID&#125;, Data.MIMETYPE + <span class="string">" = ?"</span>,</div><div class="line">                <span class="keyword">new</span> String[]&#123;GroupMembership.CONTENT_ITEM_TYPE&#125;, <span class="keyword">null</span>);</div><div class="line">        <span class="keyword">if</span> (<span class="keyword">null</span> != curosr &amp;&amp; curosr.moveToFirst()) &#123;</div><div class="line">            <span class="keyword">int</span> keyId = curosr.getColumnIndex(GroupMembership.CONTACT_ID);</div><div class="line">            <span class="keyword">int</span> keyGroupId = curosr.getColumnIndex(GroupMembership.GROUP_ROW_ID);</div><div class="line">            <span class="keyword">do</span> &#123;</div><div class="line">                String id = curosr.getString(keyId);</div><div class="line">                String groupId = curosr.getString(keyGroupId);</div><div class="line">                String groupName = groupData.get(groupId);</div><div class="line">                ContactInfo info = contactMap.get(id);</div><div class="line">                <span class="keyword">if</span> (<span class="keyword">null</span> != info &amp;&amp; !TextUtils.isEmpty(groupName)) &#123;</div><div class="line">                    info.setGroup(groupName);</div><div class="line">                &#125;</div><div class="line">            &#125; <span class="keyword">while</span> (curosr.moveToNext());</div><div class="line">        &#125;</div><div class="line">        curosr.close();</div><div class="line"></div><div class="line">        Iterator&lt;String&gt; iterator = contactMap.keySet().iterator();</div><div class="line">        <span class="keyword">while</span> (iterator.hasNext()) &#123;</div><div class="line">            String id = iterator.next();</div><div class="line">            ContactInfo info = contactMap.get(id);</div><div class="line">            System.out.println(String.format(<span class="string">"%s, %s, %s, %s."</span>, info.getName(), info.getNumber(), info.getGroup(), info.getRemark()));</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        groupData.clear();</div><div class="line">        groupData = <span class="keyword">null</span>;</div><div class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</div><div class="line">        e.printStackTrace();</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">return</span> contactMap;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="0x35-单元测试——测试异步任务"><a href="/1970/01/01/[Android]各种小记录/#0x35-单元测试——测试异步任务" class="headerlink" title="0x35 单元测试——测试异步任务"></a>0x35 单元测试——测试异步任务</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testAsynchronous</span><span class="params">()</span> </span>&#123;</div><div class="line">    <span class="keyword">try</span> &#123;</div><div class="line">        CountDownLatch signal = <span class="keyword">new</span> CountDownLatch(<span class="number">1</span>);</div><div class="line">        <span class="keyword">new</span> Thread(<span class="keyword">new</span> Runnable() &#123;</div><div class="line"></div><div class="line">            <span class="meta">@Override</span></div><div class="line">            <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span> </span>&#123;</div><div class="line">                Looper.prepare();</div><div class="line">                signal.countDown();</div><div class="line">                Looper.loop();</div><div class="line">            &#125;</div><div class="line">        &#125;).start();</div><div class="line">        signal.await();</div><div class="line">    &#125; <span class="keyword">catch</span> (InterruptedException e) &#123;</div><div class="line">        e.printStackTrace();</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="0x36-GridLayout合并"><a href="/1970/01/01/[Android]各种小记录/#0x36-GridLayout合并" class="headerlink" title="0x36 GridLayout合并"></a>0x36 GridLayout合并</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">GridLayout</span></span></div><div class="line">    <span class="attr">android:id</span>=<span class="string">"@+id/glNumber"</span></div><div class="line">    <span class="attr">android:layout_width</span>=<span class="string">"wrap_content"</span></div><div class="line">    <span class="attr">android:layout_height</span>=<span class="string">"wrap_content"</span></div><div class="line">    <span class="attr">android:layout_below</span>=<span class="string">"@+id/etPassword"</span></div><div class="line">    <span class="attr">android:layout_centerHorizontal</span>=<span class="string">"true"</span></div><div class="line">    <span class="attr">android:alignmentMode</span>=<span class="string">"alignBounds"</span></div><div class="line">    <span class="attr">android:columnCount</span>=<span class="string">"3"</span></div><div class="line">    <span class="attr">android:orientation</span>=<span class="string">"horizontal"</span></div><div class="line">    <span class="attr">android:rowCount</span>=<span class="string">"4"</span>&gt;</div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">com.ttdevs.blur.CircleButton</span></span></div><div class="line">        <span class="attr">android:id</span>=<span class="string">"@+id/cbt1"</span></div><div class="line">        <span class="attr">android:layout_width</span>=<span class="string">"64dp"</span></div><div class="line">        <span class="attr">android:layout_height</span>=<span class="string">"64dp"</span> /&gt;</div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">com.ttdevs.blur.CircleButton</span></span></div><div class="line">        <span class="attr">android:id</span>=<span class="string">"@+id/cbt2"</span></div><div class="line">        <span class="attr">android:layout_width</span>=<span class="string">"64dp"</span></div><div class="line">        <span class="attr">android:layout_height</span>=<span class="string">"64dp"</span></div><div class="line">        <span class="attr">android:layout_margin</span>=<span class="string">"10dp"</span> /&gt;</div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">com.ttdevs.blur.CircleButton</span></span></div><div class="line">        <span class="attr">android:id</span>=<span class="string">"@+id/cbt3"</span></div><div class="line">        <span class="attr">android:layout_width</span>=<span class="string">"64dp"</span></div><div class="line">        <span class="attr">android:layout_height</span>=<span class="string">"64dp"</span> /&gt;</div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">com.ttdevs.blur.CircleButton</span></span></div><div class="line">        <span class="attr">android:id</span>=<span class="string">"@+id/cbt0"</span></div><div class="line">        <span class="attr">android:layout_width</span>=<span class="string">"64dp"</span></div><div class="line">        <span class="attr">android:layout_height</span>=<span class="string">"64dp"</span></div><div class="line">        <span class="attr">android:layout_columnSpan</span>=<span class="string">"2"</span></div><div class="line">        <span class="attr">android:layout_gravity</span>=<span class="string">"right"</span> /&gt;</div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">com.ttdevs.blur.CircleButton</span></span></div><div class="line">        <span class="attr">android:id</span>=<span class="string">"@+id/cbtDel"</span></div><div class="line">        <span class="attr">android:layout_width</span>=<span class="string">"64dp"</span></div><div class="line">        <span class="attr">android:layout_height</span>=<span class="string">"64dp"</span> /&gt;</div><div class="line"><span class="tag">&lt;/<span class="name">GridLayout</span>&gt;</span></div></pre></td></tr></table></figure>
<h2 id="0x37-PopupWindow显示的时候左右不靠边（有边缝）"><a href="/1970/01/01/[Android]各种小记录/#0x37-PopupWindow显示的时候左右不靠边（有边缝）" class="headerlink" title="0x37 PopupWindow显示的时候左右不靠边（有边缝）"></a>0x37 PopupWindow显示的时候左右不靠边（有边缝）</h2><p><code>setBackgroundDrawable(new ColorDrawable(0xa0000000));</code></p>
<h2 id="0x38-EditText限制可输入小数"><a href="/1970/01/01/[Android]各种小记录/#0x38-EditText限制可输入小数" class="headerlink" title="0x38 EditText限制可输入小数"></a>0x38 EditText限制可输入小数</h2><p><code>etInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);</code></p>
<p><a href="http://stackoverflow.com/questions/4276068/how-to-make-edittext-field-for-decimals" target="_blank" rel="external"></a></p>
<h2 id="0x39-隐藏键盘"><a href="/1970/01/01/[Android]各种小记录/#0x39-隐藏键盘" class="headerlink" title="0x39 隐藏键盘"></a>0x39 隐藏键盘</h2><p>隐藏键盘貌似在onDestory中调用无效，最后自己把它写在了onStop中</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * 关闭键盘</div><div class="line"> * <span class="doctag">@param</span> context</div><div class="line"> * <span class="doctag">@param</span> windowToken</div><div class="line"> * <span class="doctag">@param</span> flag</div><div class="line"> */</div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">close</span><span class="params">(Context context, IBinder windowToken, <span class="keyword">int</span> flag)</span> </span>&#123;</div><div class="line">    InputMethodManager imm = (InputMethodManager) context</div><div class="line">            .getSystemService(Context.INPUT_METHOD_SERVICE);</div><div class="line">    imm.hideSoftInputFromWindow(windowToken, flag);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="0x40-Android-TextView-显示不全的问题"><a href="/1970/01/01/[Android]各种小记录/#0x40-Android-TextView-显示不全的问题" class="headerlink" title="0x40 Android TextView 显示不全的问题"></a>0x40 Android TextView 显示不全的问题</h2><p>代码如下，当给TextView的属性设置成match_parent的时候，text中设置的文字比较长的时候会出现显示不全的问题</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">LinearLayout</span></span></div><div class="line">    <span class="attr">android:layout_width</span>=<span class="string">"match_parent"</span></div><div class="line">    <span class="attr">android:layout_height</span>=<span class="string">"wrap_content"</span></div><div class="line">    <span class="attr">android:gravity</span>=<span class="string">"top"</span></div><div class="line">    <span class="attr">android:orientation</span>=<span class="string">"horizontal"</span></div><div class="line">    <span class="attr">android:padding</span>=<span class="string">"@dimen/global_padding_normal"</span>&gt;</div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">ImageView</span></span></div><div class="line">        <span class="attr">android:id</span>=<span class="string">"@+id/iv_health_light"</span></div><div class="line">        <span class="attr">android:layout_width</span>=<span class="string">"@dimen/detail_light_width"</span></div><div class="line">        <span class="attr">android:layout_height</span>=<span class="string">"@dimen/detail_light_height"</span></div><div class="line">        <span class="attr">android:gravity</span>=<span class="string">"center_horizontal"</span> /&gt;</div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">TextView</span></span></div><div class="line">        <span class="attr">android:id</span>=<span class="string">"@+id/tv_appraise"</span></div><div class="line">        <span class="attr">android:layout_width</span>=<span class="string">"match_parent"</span></div><div class="line">        <span class="attr">android:layout_height</span>=<span class="string">"wrap_content"</span></div><div class="line">        <span class="attr">android:layout_marginLeft</span>=<span class="string">"@dimen/global_margin_normal"</span></div><div class="line">        <span class="attr">android:gravity</span>=<span class="string">"left|top"</span></div><div class="line">        <span class="attr">android:lineSpacingExtra</span>=<span class="string">"@dimen/global_line_space"</span></div><div class="line">        <span class="attr">android:textColor</span>=<span class="string">"@color/global_gray_dark"</span></div><div class="line">        <span class="attr">android:textSize</span>=<span class="string">"@dimen/global_font_small"</span> /&gt;</div><div class="line"></div><div class="line"><span class="tag">&lt;/<span class="name">LinearLayout</span>&gt;</span></div></pre></td></tr></table></figure>
<h2 id="0x41-查看系统alarm-闹钟-队列"><a href="/1970/01/01/[Android]各种小记录/#0x41-查看系统alarm-闹钟-队列" class="headerlink" title="0x41 查看系统alarm(闹钟)队列"></a>0x41 查看系统alarm(闹钟)队列</h2><ul>
<li><p>Alarm事件队列</p>
<p>  <code>adb shell dumpsys alarm</code></p>
</li>
<li><p>查看intent</p>
<p>  <code>adb shell dumpsys activity intents</code></p>
</li>
</ul>
<p><a href="https://plus.google.com/+RomanNurik/posts/5w3Mi9EoniT" target="_blank" rel="external"></a></p>
<h2 id="0x42-singleTask与onNewIntent"><a href="/1970/01/01/[Android]各种小记录/#0x42-singleTask与onNewIntent" class="headerlink" title="0x42 singleTask与onNewIntent"></a>0x42 singleTask与onNewIntent</h2><p>singleTask与onNewIntent同时存在时，onNewIntent不是总被调用。比如：当前App启动过，第三方App再次启动时是不会调用onNewIntent的，再或者我们从任务列表中再次启动当前App也是不会触发onNewIntent的。  </p>
<p><img src="https://raw.githubusercontent.com/ttdevs/ttdevs.github.io/common/images/logo.png" alt="Create by ttdevs"></p>

          </section>
        </article>
        

       
        <div class="pager">
          
            <a class="post-prev pager-item" href="/1970/01/01/[Android]用support annotation替代enum/" >
              <strong class="article-nav-caption">上一篇</strong>
              <p class="post-nav-title">「Android」用support annotation替代enum</p>
            </a>
          
          
            <a class="post-next pager-item" href="/1970/01/01/[Flask]0x00Welcome/">
              <strong class="article-nav-caption">下一篇</strong>
              <p class="post-nav-title">「Flask」0x00Welcome</p>
            </a>
          
        </div>
        

         <!-- comments -->
        <div class="comment-section">
  
    


</div>

    </div>
    
    <aside>
        <div id="toc">
        </div>
    </aside>
    
</div>

                </div>
            </div>
        </div>
        <footer class="footer">
    <p>由<a href="http://hexo.io/" target="_blank">Hexo</a>强力驱动，搭载<a href="https://github.com/wayou/hexo-theme-gstyle">gstyle</a>主题</p>
    <p>
        &copy; 2017 ttdevs
    </p>
</footer>
<script src="/lib/jquery.js"></script>
<script src="/lib/waves.js"></script>
<script src="/lib/jquery-ui.js"></script>
<script src="/lib/jquery.tocify.js"></script>
<script src="/js/main.js"></script>

    </body>
</html>
